<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class Behavior extends Model
{
    use SoftDelete;

    // 表名
    protected $name = 'behavior';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;
    protected $deleteTime = 'deleted_at';

    //protected $append = ['status_text', 'type_text', 'category_text'];

    const POSITIVE = 1; //积极的
    const NEGATIVE = 2; //消极的

    const ABNORMAL = 0;
    const NORMAL = 1;

    public static $statusList = [
        '0' => '未启用',
        '1' => '启用',
    ];

    public static $typeList = [
        '1' => '积极的',
        '2' => '消极的',
    ];

    public function category()
    {
        return $this->belongsTo(BehaviorCategory::class, 'category_id', 'id', [], 'left');
    }

    /*public function image()
    {
        return $this->belongsTo('BehaviorImage', 'image_id', 'id', [], 'left');
    }*/

    public function getStatusTextAttr($value, $data)
    {
        return isset(self::$statusList[$data['status']]) ? self::$statusList[$data['status']] : '';
    }

    public function getTypeTextAttr($value, $data)
    {
        return isset(self::$typeList[$data['type']]) ? self::$typeList[$data['type']] : '';
    }

    public function getCategoryTypeTextAttr($value, $data)
    {
        return isset(BehaviorCategory::$typeList[$data['category_type']]) ? BehaviorCategory::$typeList[$data['category_type']] : '';
    }

}
